/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import entidades.Comentario;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author PARTICULAR
 */
public class ComentarioDao implements Dao<Comentario> {

    private EntityManager em = EMF.get().createEntityManager();
    
    @Override
    public Comentario inserir(Comentario obj) {
        synchronized (this) {
            em.getTransaction().begin();
            em.merge(obj);
            em.getTransaction().commit();
        }
        return obj;
    }

    @Override
    public Comentario pesquisar(Long obj) {
        return em.find(Comentario.class, obj);
    }

    @Override
    public void excluir(Comentario obj) {
        em.getTransaction().begin();
        em.remove(obj);
        em.getTransaction().commit();
    }

    @Override
    public List<Comentario> getAll() {
       try {
            Query q;
            q = em.createQuery("select comentario from Comentario as comentario");
            return q.getResultList();
        } catch (Exception e) {
            System.out.println("Excecao HQL.." + e);
            return null;
        }
    }
    
}
